//
//  COCommonMacro.swift
//  CocoProject
//
//  Created by Vill on 2023/11/2.
//

import Foundation
@_exported import HandyJSON
@_exported import SnapKit
@_exported import HDeviceIdentifier
@_exported import RongIMLib
@_exported import RongCloudOpenSource
@_exported import ZegoExpressEngine
@_exported import KochavaTracker

let KbaseUrl = "http://47.57.183.251:8820"
let KRongCloudAppKey = "c9kqb3rdc698j"
let KZegoTestEnv = true

// let KbaseUrl = "https://www.deliciouscuisinehone.com/app"
//let KRongCloudAppKey = "6tnym1br6ht27"
//let KZegoTestEnv = false


// 状态栏高度
func KStatusBarHeight() -> CGFloat {
    var statusBarHeight: CGFloat = 0
    if #available(iOS 13.0, *) {
        let window = UIApplication.shared.windows.filter {$0.isKeyWindow}.first
        statusBarHeight = window?.windowScene?.statusBarManager?.statusBarFrame.height ?? 0
    } else {
        statusBarHeight = UIApplication.shared.statusBarFrame.height
    }
    return statusBarHeight
}

//状态栏+导航栏高度
let KStatusAndNavBarHeight = (KStatusBarHeight() + 44.0)

// iPhoneX底部条高度+标签栏
let KTabBarAndSafeHeight = (KisPhoneX() ? 83.0 : 49.0)

// iPhoneX底部条高度
let KSafeBottomMargin = KisPhoneX() ? 34.0:0

// 是否刘海屏
func KisPhoneX() -> Bool {
    if KStatusBarHeight() > 20 {
        return true
    }
    return false
}

func PTW(_ p:Float) -> CGFloat {
    return CGFloat(p)*(SCREENWIDTH/375.0)
}

let KAppDelegate = UIApplication.shared.delegate as! AppDelegate

let kFeedbackVer     = "kFeedbackVersion"

// 用于判断是否发布
let kGetJavaVersion = "kJavaVersion"
let kFeedCheckVer   = "kcheckVerstr"

let kUploadInfo     = "uploadInfo"

let kStaticStartStr = "StaticStarString"

// 是否通过话
let kIsAllreadyCalled = "iscalled"

// 是否第一次通电话
let kIsFirstCalledBind = "isFirstCalledBindMail"

//  老用户回归金币更改
let kWelcomeBackCoinChange = "WelcomeCoinChange"

// 正在播打
let kLiveCalling = "liveCalling"

// 人工客服消息Key
let kCustomerService = "customService"

let DigiDocumentPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!

//MARK: -- Image
func KImaged(_ name: String) -> UIImage {
    return UIImage(named: name)!
}

func KUrlImaged(_ urlStr: String) -> URL? {
    return URL(string: urlStr)
}

let KBundleVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! String
let KTerms =  "https://www.deliciouscuisinehone.com/terms/"
let KPolicy =  "https://www.deliciouscuisinehone.com/policy/"


extension Notification.Name {
    /// 新人优惠
    static let NewUserRechargeNotification = Notification.Name("NewUserRechargeNotification")
    /// 退出登录倒计时关闭
    static let QuitAppTimeStopNotification = Notification.Name("QuitAppTimeStopNotification")
    /// 随机电话计时器
    static let RandomTimeRunNotification   = Notification.Name("RandomTimeRunNotification")
    /// 用户购买成功
    static let UserIsBuySuccessRecharge = Notification.Name("UserIsBuySuccess")
    /// 关注
    static let FollowFinishNoti = Notification.Name("FollowFinish")
  
    /// 获取点击空白处回收键盘的处理通知
    static let kChatTextKeyboardNeedHide = Notification.Name("kChatTextKeyboardNeedHide")
    /// 获取文本输入框值变化
    static let kChatTextKeyboardChanged = Notification.Name("kChatTextKeyboardChanged")
    
    /// 版本更新
    static let kMarketingUpNoti = Notification.Name("MarketUpNoti")
    
    // 通话结束后发通知询问是否需要绑定邮箱
    static let kIsNeedBindEmail =  Notification.Name("isNeedBindEmail")

}


// 字典转string
func dictionaryToString(dictionary: [String: Any]) -> String? {
    do {
        let jsonData = try JSONSerialization.data(withJSONObject: dictionary, options: [])
        let jsonString = String(data: jsonData, encoding: .utf8)
        return jsonString
    } catch {
        print("Error converting dictionary to string: \(error.localizedDescription)")
        return nil
    }
}

// string转字典
func stringToDictionary(jsonString: String) -> [String: Any]? {
    if let jsonData = jsonString.data(using: .utf8) {
        do {
            let dictionary = try JSONSerialization.jsonObject(with: jsonData, options: []) as? [String: Any]
            return dictionary
        } catch {
            print("Error converting string to dictionary: \(error.localizedDescription)")
            return nil
        }
    }
    return nil
}
